<template>
  <div>
    <div class="midd">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>公告通知</span>
        </div>
        <el-table :data="cannouncementlist" style="width: 100%" height="640">
          <el-table-column prop="competition_id" label="公告ID"></el-table-column>
          <el-table-column prop="competition_title" label="公告标题"></el-table-column>
          <el-table-column prop="competition_content" label="公告内容"></el-table-column>
          <el-table-column prop="create_time" label="时间" width="250"></el-table-column>
          <el-table-column fixed="right" label="操作" width="220" center>
            <template slot-scope="scope">
              <el-button
                size="small"
                type="info"
                plain
                @click="lookCam(cannouncementlist[scope.$index].competition_id)"
              >查看</el-button>
            </template>
          </el-table-column>
        </el-table>

        <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination>
      </el-card>
    </div>
    <el-dialog
      :visible.sync="centerDialogVisible"
      :before-close="closeDetail"
      width="40%"
      center
      :closeOnClickModal="false"
      title="公告详情"
    >
      <el-form :model="tabData" label-width="100px" class="demo-ruleForm" style="width:95%">
        <el-form-item label="公告ID" prop="competition_id ">
          <el-input v-model="tabData.competition_id" readonly></el-input>
        </el-form-item>
        <el-form-item label="公告标题" prop="competition_title">
          <el-input v-model="tabData.competition_title" readonly></el-input>
        </el-form-item>
        <el-form-item label="公告内容" prop="competition_content ">
          <el-input type="textarea" v-model="tabData.competition_content" readonly></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      tabPosition: "left",
      cannouncementlist: [], //赛事公告列表
      centerDialogVisible: false,
      tabData: {
        competition_id: "",
        competition_title: "",
        competition_content: ""
      }
    };
  },
  mounted() {
    this.getCannouncement();
  },
  methods: {
    //赛事公告列表
    getCannouncement() {
      var that = this;
      that.$axios
        .get("apis/admin/cannouncementlist")
        .then(function(res) {
          //console.log("赛事公告列表", res);
          if (res.status == 200) {
            if (res.data.status == 1) {
              var dataLiat = res.data.data;
              for (var i = 0; i < dataLiat.length; i++) {
                dataLiat[i].create_time = that
                  .$moment(dataLiat[i].create_time)
                  .format("YYYY-MM-DD");
              }
              that.cannouncementlist = dataLiat;
            }
            //console.log(that.cannouncementlist);
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    //查看赛事公告详情
    lookCam(id) {
      var that = this;
      that.$axios
        .post("apis/admin/cannouncementlistdetail", this.$qs.stringify({
          competition_id:id
        }))
        .then(function(res) {
          if (res.status == 200) {
            if (res.data.status == 1) {
              that.centerDialogVisible = true; 
              that.tabData = res.data.data
              that.$message({
                message: "查询成功~",
                type: "success"
              });
            }
          }
        })
        .catch(function(error) {
          console.log(error);
        });      
    },
    closeDetail() {
      this.centerDialogVisible = false;
    }
  }
};
</script>

<style lang="less" scoped>
.midd {
  width: 1200px;
  margin: 10px auto;
  .box-card {
    width: 100% !important;
  }
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both;
  }

  .box-card {
    width: 480px;
  }
  .el-pagination {
    display: flex;
    justify-content: center;
  }
}
</style>